//
//  VSFindClothesWaterLayout.m
//  UI项目2.0
//
//  Created by dlios on 15/7/15.
//  Copyright (c) 2015年 星际科技. All rights reserved.
//

#import "VSFindClothesWaterLayout.h"
#import "VSFrameGrand.h"
@implementation VSFindClothesWaterLayout


- (void)prepareLayout
{
    [super prepareLayout];
    self.delegate = (id<VSFindWaterLayoutDelegate>)self.collectionView.delegate;
}



- (CGSize)collectionViewContentSize
{
    self.LayoutHeight = [self.delegate getLayoutHeight];
    
    return CGSizeMake(SCREEN_WIDTH, self.LayoutHeight);
}

- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewLayoutAttributes *attributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
    CGFloat itmeZ = 0.040 * SCREEN_WIDTH;
    CGFloat itmeY = 0.296 * SCREEN_WIDTH;
    CGFloat itmeX = 0.016 * SCREEN_WIDTH;
    // 判断中心值
   
    if (indexPath.item % 12 == 0) {
        attributes.center = CGPointMake(itmeZ + itmeY + itmeX * 0.5, itmeZ + itmeY + itmeX * 0.5 + (indexPath.item / 12) * 6 * (itmeY + itmeX));
    }  else if (indexPath.item % 12 == 1) {
        attributes.center = CGPointMake(itmeZ + itmeY * 2.5 + itmeX * 2, itmeZ + itmeY * 0.5  + (indexPath.item / 12) * 6 * (itmeY + itmeX));
    }  else if (indexPath.item % 12 == 2) {
        attributes.center = CGPointMake(itmeZ + itmeY * 2.5 + itmeX * 2, itmeZ + itmeX + itmeY * 1.5 + (indexPath.item / 12) * 6 * (itmeY + itmeX));
    }  else if (indexPath.item % 12 == 3) {
        attributes.center = CGPointMake(itmeZ + itmeY * 0.5, itmeZ + itmeY * 2.5 + itmeX * 2 + (indexPath.item / 12) * 6 * (itmeY + itmeX));
    }  else if (indexPath.item % 12 == 4) {
        attributes.center = CGPointMake(itmeZ + itmeY * 1.5 + itmeX, itmeZ + itmeY * 2.5 + itmeX * 2 + (indexPath.item / 12) * 6 * (itmeY + itmeX));
    }  else if (indexPath.item % 12 == 5) {
        attributes.center = CGPointMake(itmeZ + itmeY * 2.5 + itmeX * 2, itmeZ + itmeY * 2.5 + itmeX * 2 + (indexPath.item / 12) * 6 * (itmeY + itmeX));
    }  else if (indexPath.item % 12 == 6) {
        attributes.center = CGPointMake(itmeZ + itmeY * 0.5, itmeZ + itmeY * 3.5 + itmeX * 3 + (indexPath.item / 12) * 6 * (itmeY + itmeX));
    }  else if (indexPath.item % 12 == 7) {
        attributes.center = CGPointMake(itmeZ + itmeY * 0.5, itmeZ + itmeY * 4.5 + itmeX * 4 + (indexPath.item / 12) * 6 * (itmeY + itmeX));
    }  else if (indexPath.item % 12 == 8) {
        attributes.center = CGPointMake(itmeZ + itmeY * 2 + itmeX * 1.5, itmeZ + itmeY * 4 + itmeX * 3.5 + (indexPath.item / 12) * 6 * (itmeY + itmeX));
    }  else if (indexPath.item % 12 == 9) {
        attributes.center = CGPointMake(itmeZ + itmeY * 0.5, itmeZ + itmeY * 5.5 + itmeX * 5 + (indexPath.item / 12) * 6 * (itmeY + itmeX));
    }  else if (indexPath.item % 12 == 10) {
        attributes.center = CGPointMake(itmeZ + itmeY * 1.5 + itmeX, itmeZ + itmeY * 5.5 + itmeX * 5 + (indexPath.item / 12) * 6 * (itmeY + itmeX));
    }  else if (indexPath.item % 12 == 11) {
        attributes.center = CGPointMake(itmeZ + itmeY * 2.5 + itmeX * 2 , itmeZ + itmeY * 5.5 + itmeX * 5 + (indexPath.item / 12) * 6 * (itmeY + itmeX));
    }
    // 判断宽高
    if (indexPath.item % 12 == 0 || indexPath.item % 12 == 8) {
        attributes.size = CGSizeMake(itmeY * 2 + itmeX, itmeY * 2 + itmeX);
    }  else {
        attributes.size = CGSizeMake(itmeY, itmeY);
    }
    
    return attributes;
}

- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
    NSMutableArray *tempArr = [[super layoutAttributesForElementsInRect:rect]mutableCopy];
    if (tempArr > 0) {
        return tempArr;
    }
    NSMutableArray *Arr = [NSMutableArray array];
    for (NSInteger i = 0; i < [self.collectionView numberOfItemsInSection:0]; i++) {
        NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:0];
        [Arr addObject:[self layoutAttributesForItemAtIndexPath:indexPath]];
    }
    return Arr;
}
- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds
{
    return YES;
}



@end
